package com.ltx.vizflowservice.controller;

import com.ltx.vizflowservice.common.convention.result.Result;
import com.ltx.vizflowservice.common.convention.result.Results;
import com.ltx.vizflowservice.util.QiNiuUtil;
import com.ltx.vizflowservice.util.UniqueRandomStringGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.UnsupportedEncodingException;

/**
 * 文件服务控制层
 */
@RestController
@Slf4j
public class FileController {

    /**
     * 文件上传
     * @param multipartFile 文件
     * @return 文件名
     */
    @PostMapping("/upload")
    public Result<String> upload(@RequestParam("file") MultipartFile multipartFile) throws UnsupportedEncodingException {
        String filename = QiNiuUtil.uploadMultipartFile(multipartFile, null);
        log.info("文件上传成功，文件名为：{}", filename);
        return Results.success(filename);
    }

}
